package com.hfh.set;

import org.junit.Test;

import java.util.Set;
import java.util.TreeSet;



public class TreeSetDemo {

    @Test
    public void test2() {

        Set<Teacher> set = new TreeSet<>();
        Teacher tea = new Teacher("zs", 20);
        Teacher tea1 = new Teacher("ls", 24);
        Teacher tea2 = new Teacher("ww", 22);
        Teacher tea3 = new Teacher("zs", 11);
        Teacher tea4 = new Teacher("ls", 30);


        set.add(tea);
        set.add(tea1);
        set.add(tea2);
        set.add(tea3);
        set.add(tea4);

        System.out.println(set);
    }

    @Test
    public void test1() {

        Set<Student> set = new TreeSet<>();
        Student stu = new Student("zs");
        Student stu1 = new Student("ls");
        Student stu2 = new Student("ww");
        Student stu3 = new Student("zl");
        Student stu4 = new Student("tq");
        Student stu5 = new Student("zs");

        /*
        如果2个对象调用equals方法返回了false, 那么就表示2个对象不相同
        既然2个对象不相同, 在set里面肯定是都要保存进去
        这样的话业务代码就前后矛盾的

        compareTo 如果返回0, equals就一定要返回true
        compareTo使用了哪些属性, equals也只能使用这些属性
         */
        boolean flag = stu.equals(stu5);
        System.out.println(flag);

        set.add(stu);
        set.add(stu1);
        set.add(stu2);
        set.add(stu3);
        set.add(stu4);
        set.add(stu5);

        System.out.println(set);
    }

    public static void main(String[] args) {
        Set<String> set = new TreeSet<>();

        System.out.println("a".compareTo("aa"));// -1
        System.out.println("a".compareTo("c"));// -2
        set.add("a");
        set.add("aa");
        set.add("c");
        set.add("b");

        System.out.println(set);//[a, aa, b, c]


        Set<Integer> set1 = new TreeSet<>();

        set1.add(5);
        set1.add(4);
        set1.add(2);
        set1.add(6);

        System.out.println(set1);//[2, 4, 5, 6]

    }
}
